package com.pe.controller.user;

import com.pe.controller.IService;
import com.pe.dao.user.UserFactory;
import com.pe.dao.user.UserFactoryImpl;
import com.pe.model.user.User;
import com.pe.model.user.UserImpl;
import com.pe.service.param.user.LoginServiceParam;
import com.pe.service.response.user.LoginResponse;

public class Login implements IService<LoginServiceParam>{

	@Override
	public LoginResponse handleService(LoginServiceParam serviceParam) {
		LoginResponse response= LoginResponse.getInstance();
		String email=serviceParam.getEmail();
		String password = serviceParam.getPassword();

		User user = new UserImpl(email);
		UserFactory uf= new UserFactoryImpl();
		user =  uf.getUser(user);
		
		//TODO: MUST Need to validate strictly 
		if(user == null){
			 response.generateSuccessResponse(serviceParam, null);
			 return response;
		}
		String pass=user.getPassword();
		
		if(password.equals(pass)){
			response.generateSuccessResponse(serviceParam, null);
		}else{
			response.generateFailureResponse(serviceParam, null);
		}
		return response;
	}
}
